package com.test.nio.select;

import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.channels.SelectionKey;
import java.nio.channels.Selector;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;

/**
 * @Description:
 * @Author: yangzhiwei
 * @Date: 2021/8/2 10:01
 */
public class SelectServer {
    public static void main(String[] args) throws IOException {
        ServerSocketChannel serverSocketChannel = ServerSocketChannel.open();

        // 设置 背压
        serverSocketChannel.bind(new InetSocketAddress(8088), 3);
        SocketChannel socketChannel = serverSocketChannel.accept();
        socketChannel.configureBlocking(false);
        Selector selector = Selector.open();
        socketChannel.register(selector, SelectionKey.OP_ACCEPT);

        socketChannel.register(selector,SelectionKey.OP_ACCEPT | SelectionKey.OP_READ);

    }
}
